package com.benmei.weike.web;

import com.benmei.weike.common.Constants;
import com.benmei.weike.entity.VersionUpgrade;
import com.benmei.weike.service.VersionUpgradeService;
import com.benmei.weike.util.JsonUtil;
import com.nativetalk.base.RetInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Peter on 2018/11/10.
 * 学生账户2
 */
@RestController
public class VersionUpgradeController {
    public static final Logger logger = LoggerFactory.getLogger(VersionUpgradeController.class);

    @Autowired
    private VersionUpgradeService versionUpgradeService;

    // 通过注册码注册
    @RequestMapping(value = "/v5.0/app/version", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo appVersionUpgrade(@RequestBody VersionUpgrade versionUpgrade) {
        try {
            //打印入参
            logger.info(Constants.prefix_out + JsonUtil.toJson(versionUpgrade));
            VersionUpgrade obj = versionUpgradeService.appVersionUpgrade(versionUpgrade);
            RetInfo retInfo = RetInfo.getSuccessInfo(obj);
            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

}
